package com.sky.proxy.jdkDynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 通用 生成代理人
 * <br>
 *
 * @author : wushikai
 * <p>
 * date : 2020-12-11
 *
 */
public class StarProxyGenerator<T  extends IStar> implements InvocationHandler {

    private T target;

    public StarProxyGenerator(T target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (proxy!= null ){
            System.out.println("我是通用的代理人, 我现在为 " + target.getName() + "干活");
        }
        System.out.println(" 卖票 ");
        method.invoke(target, args);
        System.out.println(" 分账  ");
        return proxy;
    }
}
